package com.example.springaop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
@Aspect
@Order(1)
public class AspectDemo2 {
    @Before("com.example.springaop.AspectDemo.pt()")
    public void doBefore() {
        log.info("方法执行前 doBefore2()");
    }

    @After("execution(* com.example.controller.*.*(..))")
    public void doAfter() {
        log.info("方法执行后 doAfter2()");
    }

    @Around("execution(* com.example.controller.*.*(..))")
    public Object doAround(ProceedingJoinPoint pj) throws Throwable {
        log.info("方法执行前 doAround2()");
        Object result = pj.proceed();
        log.info("方法执行后 doAround2()");
        return result;
    }

    @AfterReturning("execution(* com.example.controller.*.*(..))")
    public void doAfterReturn() {
        log.info("方法执行后 doAfterReturn2()");
    }

    @AfterThrowing("execution(* com.example.controller.*.*(..))")
    public void doAfterThrow() {
        log.info("方法执行后 doAfterThrow2()");
    }
}